# -*- coding:utf-8 -*-
from django.db import models
from django.utils.translation import ugettext as _
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db.models import Q
import datetime
from this_site.models import Staff
from washing.models import BaseClass, Client
from django.db.models.signals import post_save

class Service(BaseClass):   
    class Meta:
        verbose_name = u'услугу'
        verbose_name_plural = u'услуги'
        
#    price = models.FloatField(u'цена')

class STOJournal(models.Model):
    datetime = models.DateTimeField(u'дата и время', auto_now=True, auto_now_add=True)
    client = models.ForeignKey(Client, verbose_name = u'клиент', blank=True, null=True)
    service = models.ManyToManyField(Service, verbose_name = u'услуги')
    sum = models.FloatField(u'сумма')
    
    class Meta:
        verbose_name = u'запись'
        verbose_name_plural = u'журнал СТО'
        
    def __unicode__(self):
        return u'%s' % (self.datetime)
    
    def get_service_str(self):
        result = ''
        for obj in self.service.all():
            result += '%s<br/>' % obj.name
        return result
    get_service_str.short_description = u'Услуги'
    get_service_str.allow_tags = True